﻿using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EntityFrameworkETL.Test
{
    public static class TestExtensions
    {
        public static DbCommand CreateWorldCommand(string name)
        {
            const string sqlWorld = @"INSERT [dbo].[Worlds]([Name])
VALUES (@0)
SELECT [Id]
FROM [dbo].[Worlds]
WHERE @@ROWCOUNT > 0 AND [Id] = scope_identity()";
            var command = new SqlCommand(sqlWorld);
            command.Parameters.Add(new SqlParameter("@0", name));
            return command;
        }

        public static DbCommand CreatePersonCommand(string name, int fakeWorldId)
        {
            const string sqlPerson = @"INSERT [dbo].[People]([Name], [WorldId])
VALUES (@0, @1)
SELECT [Id]
FROM [dbo].[People]
WHERE @@ROWCOUNT > 0 AND [Id] = scope_identity()";
            var command = new SqlCommand(sqlPerson);
            command.Parameters.Add(new SqlParameter("@0", name));
            command.Parameters.Add(new SqlParameter("@1", fakeWorldId));
            return command;
        }

        public static DbCommand CreateJobComamand(string name, int fakePersonId)
        {
            const string sqlJob = @"INSERT [dbo].[Jobs]([Name], [PersonId])
VALUES (@0, @1)
SELECT [Id]
FROM [dbo].[Jobs]
WHERE @@ROWCOUNT > 0 AND [Id] = scope_identity()";
            var command = new SqlCommand(sqlJob);
            command.Parameters.Add(new SqlParameter("@0", name));
            command.Parameters.Add(new SqlParameter("@1", fakePersonId));
            return command;
        }
    }
}
